#{extends 'main.html'/}
<link rel="stylesheet" href="/public/themes/default/default.css" />
<script charset="utf-8" src="/public/kindeditor-min.js"></script>
<script charset="utf-8" src="/public/lang/zh_CN.js"></script>
<div class="l-clear"></div>
<div id="maingrid" style="margin-top:1px"></div> <br />
<div style="display:none;"></div>
<div id="detail" style="display:none;"><form id="mainform" method="post"></form></div>
<div id="inputForm">
    <form id="inputForms" method="post">
        <table>
            <tr><td>　名字：<input type="text" name="medical_insurance.Name"/></td><td>　序列号：<input type="text" name="medical_insurance.SerialNo"/></td>
            <td><input type="hidden" name="medical_insurance.id"/></td>
            </tr>
        </table>
        </br>
        <table>
                　　<tr>
                <td>　详细</br>　内容：</td>
                <td><textarea name="medical_insurance.Measures" id="content" style="width:1000px;height:200px;visibility:hidden;">请输入医保详细内容。。。</textarea></td>
            </tr>
        </table>
    </form>
</div>
<script type="text/javascript">
    $(function () {
      
        var typeData = [{ type: 1, text: '临床' }, { type: 2, text: '医技'},{ type: 3, text: '行政'},{ type: 4, text: '后勤'},{ type: 5, text: '窗口'}];
       
        var manager, grid;

        function f_initGrid() 
        {
            grid = manager = $("#maingrid").ligerGrid({
                columns: [
                    { display: '编号', name: 'id', width: 50, type: 'int' },
                    { display: '名称', name: 'Name', width: 100, type: 'textarea' },
                    { display: '序列号', name: 'SerialNo', width: 150, type: 'string', type: 'textarea'}
                ],

                url: "yibao/json",  method: "GET",                       
                width: '100%',height:"40%", 
                toolbar: { items: [
                       { text: '增加', click: addRow, icon: 'add' },
                        { line: true },
                        { text: '保存', click: modifyRow, icon: 'modify' },
                        { line: true },
                        { text: '删除', click: deleteRow, icon: 'delete' },
                        { line: true },
                        { text: '复原', click: replay, icon: 'back' },
                        { line: true }
                    ] }
            });         	
        }
        
        f_initGrid();
        
        
         grid.bind('selectRow', function (data)
        {
            showDetail(data);
             editor.html(data.Measures);
        });
        
        function replay(){
            showDetail({});
            editor.html('');
        }

        function showDetail(data){
            
            if(data != null){
                
                $("[name$=Name]").val(data.Name);
                $("[name$=SerialNo]").val(data.SerialNo);
               
            }else{
                $("[name$=id]").val();
                $("[name$=Name]").val();
                $("[name$=SerialNo]").val();
            }
            
        }
      
        
        function f_reload() {
            grid.loadData();
        }
        
        function getSelected()
        { 
            var row = manager.getSelectedRow();
            if (!row) { alert('请选择行'); return; }
            alert(JSON.stringify(row));
        }
        
        function getData()
        { 
            var data = manager.getData();
            alert(JSON.stringify(data));
        }
        
        function addRow()
        {
          save();
        }
        
        function modifyRow()
        {
            var selected = grid.getSelected();
            if (!selected) { LG.tip('请选择行!'); return }
            $("[name$=id]").val(selected.id);
            save();

        }
        
        function deleteRow()
        {
            jQuery.ligerDialog.confirm('确定删除吗?', function (confirm) {
                if (confirm) f_delete(); });
        }
        
        function f_delete() {
            var selected = grid.getSelected();
            if (selected) {
                $.ajax({
                    url: 'yibao/' + selected.id,
                    type: 'DELETE',                  
                    loading: '正在删除中...',                  
                    success: function () {
                        //LG.showSuccess('删除成功');
                        LG.tip('删除成功!');
                        f_reload();
                    },
                    error: function (message) {
                        LG.showError(message);
                    }
                });
            }
            else {
                LG.tip('请选择行!');
            }
        }
        
        var detailWin = null, curentData = null, currentIsAddNew;
        var mainform = $("#mainform");
	    
      
        
        function save()
        {
            $("#inputForms").validate();
            $("#content").val(editor.html());
            $.ajax({
                loading: '正在保存数据中...',
                type: 'POST',
                url: 'yibaos',                  
                data: $("#inputForms").serialize(),
                success: function ()
                {
                    grid.loadData();
                    LG.tip('保存成功!');
                },
                error: function (message)
                {
                    LG.tip(message);
                }
            });
        }

    })
        
    var editor,editor２,editor3,editor4,editor4;
    KindEditor.ready(function(K) {
        editor = K.create('#content', {
            allowFileManager : true
        });
    });
</script>
